#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
    import elsLibs.ShotInfoFromFile as elssif
    reload(elssif)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckELSFrameRange(CheckBase):
    def __init__(self):
        super(CheckELSFrameRange, self).__init__()
        pass

    def init_file(self):
        scene_name = mu.sceneName()
        sif = elssif.ShotInfoFromFile(scene_name)
        self.cam_st = sif.get_cam_st
        self.cam_et = sif.get_cam_et
        self.get_cam_file = sif.get_camera_abc_file

    def get_file_st(self):
        ast = cmds.playbackOptions(q=True, ast=True)
        return ast

    def get_file_et(self):
        aet = cmds.playbackOptions(q=True, aet=True)
        return aet

    def check(self):
        current_file = mu.sceneName()
        if not current_file:
            result_log = u'Error: 当前文件未保存!'
            return result_log
        if current_file.startswith('els_'):
            result_log = u'Error: 当前文件非els项目镜头规则!'
            return result_log
        try:
            self.init_file()
        except:
            result_log = u'Error:当前文件不符合ELS项目资产文件命名规则'
            return result_log
        if self.get_cam_file:
            result_log = 'Error:'
            if self.cam_st != self.get_file_st():
                result_log += u'起始帧和发布的相机不匹配;'
            if self.cam_et != self.get_file_et():
                result_log += u'结束帧和发布的相机不匹配;'

            if self.cam_st == self.get_file_st() and self.cam_et == self.get_file_et():
                result_log = u'Succeed:没有问题\n'
        else:
            result_log = u'Warning:未查询到发布的相机文件!'
        return result_log

    def fix(self):
        pass